global class SubmitUtil{
	static String testVar1 = '';
	
	
	Webservice static String createInquiryObject(String plandocumentId,String reason,String sub,String description,String approver){
	    String str = null;
	    String firstName = null;
	    String lastName = null;
	    Sales_Contract__c[] planDoc = null;
	    
	    System.LoggingLevel level = LoggingLevel.DEBUG;
	    
	    try
	    {
	        planDoc = [SELECT Id, Name, Status__c, FirstName__c, LastName__c, Submit_Inquiry__c FROM Sales_Contract__c sc where sc.Id = :plandocumentId];
	        if(planDoc.size() > 0 && planDoc[0] ==null)
	        {   
	            return 'List has no rows'; 
	        }
	        if(planDoc.size() > 0)
	        {
	            str=planDoc[0].FirstName__c;
	            firstName=planDoc[0].FirstName__c;
	            lastName=planDoc[0].LastName__c;
	            planDoc[0].Submit_Inquiry__c=true; 
	            planDoc[0].Status__c='Inquiry Submitted';
	            
	            if(testVar1 != '' && testVar1.length() > 0)
	            {
	                planDoc[0].Level1__c = '005400000011epc';
	                planDoc[0].Level2__c = '005400000011epc';
	                planDoc[0].Level3__c = '005400000011epc';
	                planDoc[0].Level4__c = '005400000011epc';
	                planDoc[0].Level5__c = '005400000011epc';
	                planDoc[0].Level6__c = '005400000011epc';
	                planDoc[0].Level7__c = '005400000011epc';
	                planDoc[0].Level8__c = '005400000011epc';
	                planDoc[0].Level9__c = '005400000011epc';
	                planDoc[0].Level10__c = '005400000011epc';
	                planDoc[0].Level11__c = '005400000011epc';
	                planDoc[0].Level12__c = '005400000011epc';
	                planDoc[0].Level13__c = '005400000011epc';
	                planDoc[0].Level14__c = '005400000011epc';
	                planDoc[0].Level15__c = '005400000011epc';
	                planDoc[0].Final_Approver__c = '005400000011epc';
	                planDoc[0].Final_Approver_Date__c = Date.valueof('2008-06-26');
	            }
	    
	            if(testVar1 == 'Published')
	            {
	                planDoc[0].Status__c = 'Published';
	            }
	            if(testVar1 == 'Plan Approved 1')
	                planDoc[0].Status__c = 'Plan Approved by Engineering Callidus';
	            if(testVar1 == 'Plan Rejected 1')
	                planDoc[0].Status__c = 'Plan Rejected by Engineering Callidus';
	    
	            if(testVar1 != '' && testVar1.length() > 0)
	            {
	                planDoc[0].Level1__c = '005400000011eqL';
	                planDoc[0].Level2__c = '005400000011eqL';
	                planDoc[0].Level3__c = '005400000011eqL';
	                planDoc[0].Level4__c = '005400000011eqL';
	                planDoc[0].Level5__c = '005400000011eqL';
	                planDoc[0].Level6__c = '005400000011eqL';
	                planDoc[0].Level7__c = '005400000011eqL';
	                planDoc[0].Level8__c = '005400000011eqL';
	                planDoc[0].Level9__c = '005400000011eqL';
	                planDoc[0].Level10__c = '005400000011eqL';
	                planDoc[0].Level11__c = '005400000011eqL';
	                planDoc[0].Level12__c = '005400000011eqL';
	                planDoc[0].Level13__c = '005400000011eqL';
	                planDoc[0].Level14__c = '005400000011eqL';
	                planDoc[0].Level15__c = '005400000011eqL';
	                planDoc[0].Final_Approver__c = '005400000011eqL';
	                planDoc[0].Final_Approver_Date__c = Date.valueof('2008-06-26');
	            }
	            if(testVar1 == 'Plan Approved 2')
	                planDoc[0].Status__c = 'Plan Approved by Jack Hill';
	            if(testVar1 == 'Plan Rejected 2')
	                planDoc[0].Status__c = 'Plan Rejected by Jack Hill';
	            
	        }    
	    }
	    catch(DmlException dme)
	    {
	        return str+' '+dme;
	    }
	
	    try
	    {
	        update planDoc;
	    }
	    catch(DmlException dme)
	    {
	        return str+' '+dme;
	    }
	
	    URL__c[] url = [SELECT Id, Url_Value__c FROM URL__c];
	
	    Plan_Document_Inquiry__c pdInquiry = null;
	    pdInquiry = new Plan_Document_Inquiry__c();
	    pdInquiry.Plan_Document__c=plandocumentId;
	    pdInquiry.Reason__c=reason;
	    pdInquiry.Description__c=description;
	    pdInquiry.Name=sub;
	    pdInquiry.InquiryCreated__c=System.now();
	    pdInquiry.InquiryStatus__c='Pending';
	    if(url.size() > 0)
	    {
	        pdInquiry.Url__c=url[0].Url_Value__c;
	    }
	    str=''+'after assignment'+pdInquiry.Reason__c+pdInquiry.Description__c+pdInquiry.Name;
	    try
	    {
	        insert pdInquiry;
	    }
	    catch(DmlException dme)
	    {
	        return str+dme;
	    }
	    
	    if(approver != 'Administrator')
	    {
	        Approval.ProcessSubmitRequest request =new Approval.ProcessSubmitRequest();
	        request.setObjectId(pdInquiry.id);
	        Approval.ProcessResult result = Approval.process(request);
	    }
	    
	 
	return 'success';
	
	}
          
	Webservice static Boolean hasManager(ID userId)
	{
		User[] u = [select ManagerId from User where id = :userId];
		if(u[0].ManagerId != null)
			return true;
		return false;
	}
	          
    static testMethod void testSubmitUtil() 
    {
        testVar1 = 'Published';
        createInquiryObject('a0E40000000n1ev','test','test','test','Administrator');
        testVar1 = 'Plan Approved 1';
        createInquiryObject('a0E40000000n1ev','test','test','test','Administrator');
        testVar1 = 'Plan Rejected 1';
        createInquiryObject('a0E40000000n1ev','test','test','test','Administrator');
        testVar1 = 'Plan Rejected 2';
        createInquiryObject('a0E40000000n1ev','test','test','test','Administrator');
        testVar1 = 'Plan Approved 2';
        createInquiryObject('a0E40000000n1ev','test','test','test','Administrator');
    
//        createInquiryObject('a0E40000000n1ev','test','test','test','Administrator');
    }
    
}